using System;
using System.Collections;
using System.IO;

namespace SvmNFold
{
	class Class
	{
		[STAThread]
		static void Main(string[] args)
		{
			if (args.Length < 4)
			{
				Console.Error.WriteLine("Provide the name of the input file\nTraining pattern name\nTest pattern name\nFile name template\n");
				return;
			}
			string inputFileName = args[0];
			string trainingPattern = args[1];
			string testPattern = args[2];
			string fileNameTemplate = args[3];

			Console.WriteLine(inputFileName);
			Console.WriteLine(trainingPattern);
			Console.WriteLine(testPattern);
			Console.WriteLine(fileNameTemplate);

			StreamReader reader = null;
			ArrayList list = new ArrayList();
			int lineNumber = 0;
			string line;
			try
			{
				reader = new StreamReader(inputFileName);

				while((line = reader.ReadLine()) != null)
				{
					list.Add(line);
					lineNumber++;
				}

				Console.WriteLine(lineNumber + " lines read");

				new Vector2SvmConverter.ShuffleTrainTest(list,trainingPattern,testPattern,fileNameTemplate).ShuffleAndWrite();
			}
			catch(IOException ex)
			{
				Console.Error.WriteLine(ex.Message);
			}
			catch(Exception ex)
			{
				Console.Error.WriteLine(ex.Message);
			}
			finally
			{
				if (reader != null) reader.Close();
			}
		}
	}
}
